<template>
  <div class="container" @click="hdGallaryClick">
    <div class="wrapper">
      <swiper :options="swiperOption" ref="mySwiper">
        <!-- slides -->
        <!-- swiplerList 改成 list 通过属性传进来-->
        <swiper-slide v-for="(item, index) in imgs" :key="index">
          <img class="gallary-img" :src="item" />
        </swiper-slide>
        <div class="swiper-pagination swiper-pagination-bullets" slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Gallary',
  props: {
    imgs: {
      type: Array,
      default() {
        return []
      },
    },
  },
  data() {
    return {
      swiperOption: {
        pagination: {
          el: '.swiper-pagination',
          type: 'fraction',
        },
        observeParents: true, // 将 observe 应用于 Swiper 的父元素。当Swiper的父元素变化时，例如 window.resize，Swiper 更新。
        observer: true, // 启动动态检查器(OB/观众/观看者)，当改变 swiper 的样式（例如隐藏/显示）或者修改 swiper 的子元素时，自动初始化 swiper。默认 false，不开启，可以使用 update() 方法更新。
        loop: true, // 以下4个处理自动滚动
        autoplay: {
          disableOnInteraction: false, // 解决手势拖动后，不在自动播放
          delay: 3000, //3秒切换一次
        },
      },
    }
  },
  methods: {
    hdGallaryClick() {
      this.$emit('closeGallary')
    },
  },
  computed: {},
}
</script>

<style lang="scss" scoped>
.container ::v-deep .swiper-container {
  overflow: inherit;
}
.container ::v-deep .swiper-wrapper {
  align-items: center;
}
.container {
  z-index: 99;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: #000;
}
.container .wrapper {
  height: 0;
  width: 100%;
  padding-bottom: 100%;
}
.container .wrapper .gallary-img {
  width: 100%;
  margin-top: 1rem;
}
.container .wrapper .swiper-pagination {
  color: #fff;
  bottom: -1rem;
}
</style>
